<?php

/**
 * @author Xubi Nguyen
 * @copyright 2011
 */

class login_model extends CI_Model
{
	function __construct()
	{
		parent::__construct('dangnhap');
	}
    
	function Get($session)
	{
		$login = $this->where('sessionid',"'".$session."'",false)->find();
        if($login->sessionid=='')
            return false;
        else
        { 
           $data = json_decode($login->account ,true);   
           $data['time'] = $login->time;
           return $data;       
        }
		return false;
	}
    
    function SetTime($session)
	{
		$this->where('sessionid',"'".$session."'",false)->update(array('time'=>gmdate("Y-m-d H:i:s",time()+7*3600)));
       
	}	
    
    function Del($session)
	{
		$this->where('sessionid',"'".$session."'",false)->delete();
       
	}
    
    function DeleteAll($time)
	{
	   $datenow = gmdate("Y-m-d H:i:s",time()+7*3600);
       $timenow = strtotime($datenow);
       $timesub = $timenow - $time;
	   $this->where('time <= ',date("Y-m-d H:i:s",$timesub))->delete();
	}
}
?>